/**
 * @author Linrui
 * @since 2011-06-01
 * 负责首页1级子类别的数据加载
 */
package com.qeado.index.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.qeado.product.service.ProductService;
import com.qeado.sort.model.Sort;
import com.qeado.sort.service.SortService;
import com.qeado.util.PageHelper;

@Scope("session")
@Controller
public class SubAction extends ActionSupport {

	@Autowired
	private ProductService productService;
	
	private PageHelper newSell; // 最新发布的出售信息
	private PageHelper newBuy; // 最新发布的采购信息
	
	private String style = "1"; // 分类使用的主题	
	private String typeCode; // 类型编码

	public String getTypeCode() {
		return typeCode;
	}

	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}
	
	public PageHelper getNewSell() {
		return newSell;
	}

	public void setNewSell(PageHelper newSell) {
		this.newSell = newSell;
	}

	public PageHelper getNewBuy() {
		return newBuy;
	}

	public void setNewBuy(PageHelper newBuy) {
		this.newBuy = newBuy;
	}

	// 查询该大类下的对应2级3级分类
	@Override
	public String execute() throws Exception {
		/* 加载最新发布的出售物品*/
		newSell = productService.listAll(1, 10, "create_date", "desc", "1"); 
		/* 加载最新发布的采购物品*/
		newBuy = productService.listAll(1, 10, "create_date", "desc", "2"); 
		// 根据主题选择一级大类
		switch (Integer.parseInt(style)) {
			case 1:
				typeCode = "ZA"; // 农产品
				break;
			case 2:
				typeCode = "ZB"; // 水产品
				break;
			case 3:
				typeCode = "ZC"; // 茶叶
				break;
			case 4:
				typeCode = "ZD"; // 药材
				break;
			case 5:
				typeCode = "ZE"; // 花卉
				break;
			case 6:
				typeCode = "ZF"; // 农用物资
				break;
			case 7:
				typeCode = "ZG"; // 粮食
				break;
			case 8:
				typeCode = "ZH"; // 动物肉类
				break;
			default:
				typeCode = "%";
		}
		return super.execute();
	}
	
}
